Skip to content

Conversation

@ValdikSS
Copy link
Member

@ValdikSS ValdikSS commented May 26, 2025

Add new dithering (halftone) algorithms in addition to the default Ghostscript one.
Controlled either with halftone-type job option or cupsHalftoneType PPD option.

  • Stochastic algotirhm is implemented in stocht.ps Ghostscript library, just include it if cupsHalftoneType is set to yes/true/on/stochastic.
  • Foo2zjs algorithm is a PostScript code taken from foo2zjs-pstops file (don't know the name of the algorithm)
  • Threshold algorithm

Default algorithm

dither-default

Stochastic algorithm

dither-stoh

Foo2zjs algorithm

dither-foo2zjs

@ValdikSS
Copy link
Member Author

ValdikSS commented May 26, 2025

Is it fine to introduce new prefixed PPD option? Some proprietary filters already use Halftone and HalftoneType, so I decided to go with cupsHalftoneType, even if it only applies to Ghostscript-based filter.

cups-filters 1.x: OpenPrinting/cups-filters#642

Copy link
Member

@zdohnal zdohnal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks ok on syntax side of things, there are some space/tab issues against applied code style.

Regarding functionality I can't say, since I don't fully understand the best practices and it would be great if it was reviewed by an additional person.

@zdohnal
Copy link
Member

zdohnal commented May 28, 2025

Either way, thank you for the PR, @ValdikSS !

Ad new prefixed option - I would say it is fine, but probably @michaelrsweet should know more.

@ValdikSS ValdikSS force-pushed the ghostscript-dither-repo branch from c17cb8f to 5a71e53 Compare May 29, 2025 17:27
@ValdikSS ValdikSS requested a review from zdohnal May 29, 2025 17:41
Copy link
Member

@zdohnal zdohnal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one line scopes should not be enveloped by brackets, otherwise it looks great!

ValdikSS added 2 commits May 30, 2025 12:39
…thms

Add new dithering (halftone) algorithms in addition to the default Ghostscript
one.
Controlled either with `halftone-type` job option or `cupsHalftoneType` PPD
option.

- Stochastic algotirhm is implemented in `stocht.ps` Ghostscript library,
  just include it if cupsHalftoneType is set to yes/true/on/stochastic.
- Foo2zjs algorithm is a PostScript code taken from foo2zjs-pstops file
  (don't know the name of the algorithm)
Similar to pdftoraster implementation.
@ValdikSS ValdikSS force-pushed the ghostscript-dither-repo branch from 5a71e53 to 71742d2 Compare May 30, 2025 09:41
@ValdikSS ValdikSS requested a review from zdohnal May 30, 2025 09:41
Copy link
Member

@zdohnal zdohnal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@michaelrsweet / @tillkamppeter can you review this from functioanity POV (meaning whether halftone implementation is correct)? I have check foo2zjs code and the Postscript code here is matching this PR, bi-level looks feasible with my little knowledge of Postscript, stocht.ps from ghostscript is accessible on machines which includes the script, so LGTM.

@tillkamppeter
Copy link
Member

Principally, this code looks OK to me.

Some remarks:

  1. When not using the new options, does one get the same results as before?
  2. Will the halftoning also work if the input into Ghostscript is PDF?
  3. As long as the new halftoming options are not represented in print dialogs, nearly no user will use them, as they do not read the documentation of libcupsfilter
  4. The feature will only be available if the job goes through Ghostscript. Jobs with a raster or image format as input for example will not be affected by the new halftoning settings.

@ValdikSS
Copy link
Member Author

When not using the new options, does one get the same results as before?

Yes.

Will the halftoning also work if the input into Ghostscript is PDF?

Yes, I've tested on PDF files only.

As long as the new halftoming options are not represented in print dialogs, nearly no user will use them, as they do not read the documentation of libcupsfilter

Indeed, proper integration would be much better. Any suggestions?

Jobs with a raster or image format as input for example will not be affected by the new halftoning settings.

poppler already has bi-level halftoning, and its default is much better than ghostscript's default.

@tillkamppeter tillkamppeter merged commit 2a84dee into OpenPrinting:master Sep 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants